//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<IGuiControl.h>
///	@path	~/src/gui/
///	@date	2008/05/20
///	@desc	.

#pragma once

#include "xeres.h"

#include "gui/IGuiComp.h"

namespace xeres {

	/*! 
		\class	IGuiControl
		\brief
	*/
	class IGuiControl : public IGuiComp
	{
	protected:

		/// \ctor
		IGuiControl( const Rect<int>& placement , bool refreshFocus , bool refreshHover , bool activeOrder );

	public:

		/// \dtor
		virtual ~IGuiControl( void );

		DECL_IOBJECT_INTERFACE( IGuiControl , IGuiComp );

	public:

		/// \name Default Implementation of XControl
		//@{

		/// \brief	Get position of component (in relative coordinate).
		virtual Pair<int> GetPosition( void );

		/// \brief	Set position of component.
		virtual bool SetPosition( const Pair<int>& pos );

		/// \brief	Get screen position.
		virtual Pair<int> GetScreenPosition( void );

		/// \brief	Get size of component.
		virtual Pair<int> GetSize( void );

		/// \brief	Set size of component.
		virtual bool SetSize( const Pair<int>& size );

		/// \brief	Get rect (in local coordinate).
		Rect<int> GetRect( void );

		/// \brief	Get bound (in local coordinate).
		Rect<int> GetBound( void );

		/// \brief	Get placement rect (in parent coordinate).
		virtual Rect<int> GetPlacement( void );

		/// \brief	Set placement.
		virtual bool SetPlacement( const Rect<int>& placement );

		/// \brief	Get parent component.
		virtual RefWeak<IGuiForm> GetParent( void );

		/// \brief	Set parent component.
		virtual bool SetParent( RefWeak<IGuiForm> parent );

		/// \brief	Get component visibility.
		virtual bool GetVisible( void );

		/// \brief	Set component visibility.
		virtual bool SetVisible( bool visible );

		/// \brief	Get component enable (to input).
		virtual bool GetEnable( void );

		/// \brief	Set component enable.
		virtual bool SetEnable( bool enable );

		/// \brief	Get focus state.
		virtual bool GetFocus( void );

		/// \brief	Set focus state.
		virtual bool SetFocus( bool focus );

		/// \brief	Get mouse hover state.
		virtual bool GetHover( void );

		/// \brief	Close control.
		virtual void Close( void );

		//@}

		/// \name Message Passing
		//@{

		///	\brief	Process key input message.
		virtual HandleInput OnKeyInput( Updater& updater );

		///	\brief	Process mouse input message.
		virtual HandleInput OnMouseInput( Updater& updater );

		/// \brief	Call when mouse enter component.
		virtual void OnMouseEnter( Updater& updater , RefWeak<IGuiComp> last );

		/// \brief	Call when mouse leave component.
		virtual void OnMouseLeave( Updater& updater , RefWeak<IGuiComp> next );

		/// \brief	Call when mouse hover component.
		virtual void OnMouseHover( Updater& updater );

		/// \brief	Call when focus in.
		virtual void OnFocusIn( Updater& updater , RefWeak<IGuiComp> last );

		/// \brief	Call when focus out.
		virtual void OnFocusOut( Updater& updater , RefWeak<IGuiComp> next );

		/// \brief	Call when close window.
		virtual void OnClose( void );

		//@}

		/// \name Presentation Manipulation
		//@{

		/// \brief	Tick update.
		virtual void Tick( Updater& updater , float dTime );

		/// \brief	Draw XGUI component to composition.
		virtual void Draw( Composition& composition );

		//@}

		/// \brief	Enable active order (change order while active).
		void EnableActiveOrder( bool enable );

		/// \brief	Helper function to request update.
		void UpdateControl( void );

	protected:

		/// \name	XControl Interface
		//@{

		/// \brief	Call when size changed.
		virtual void OnSize( void );

		/// \brief	Call when pos changed.
		virtual void OnPos( void );

		/// \brief	Call when control is about to appear or hide.
		virtual void OnVisible( bool visible );

		/// \brief	Call when control is about to enable or disable.
		virtual void OnEnable( bool enable );

		/// \brief	Call when focus is about to change.
		virtual void OnFocus( bool focusing );

		/// \brief	Call when mouse over control.
		virtual void OnMouseOver( bool hovering );

		//@}

	protected:

		//@ data
		Pair<int>			m_position;
		Pair<int>			m_size;

		RefWeak<IGuiForm>	m_parent;

		// states
		bool				m_enable;
		bool				m_visible;
		bool				m_focus;
		bool				m_hover;

		bool				m_activeOrder;
		bool				m_clicked;
		bool				m_refreshFocus;
		bool				m_refreshHover;
	};

} // namespace xeres
